package constant

const (
	UM = 1 // 变动对象 用户余额(user_money)

	INC = 1 // 增加
	DEC = 2 // 减少

	UmIncAdmin    = 200 //  用户余额增加类型
	UmIncRecharge = 201

	// UmDecAdmin 用户余额减少类型
	UmDecAdmin          = 100
	UmDecRechargeRefund = 101

	// 退款状态
	RefundStatusRefunded  = 1 // 已退款
	RefundStatusRefunding = 0 // 退款中
	RefundStatusFail      = 2 // 退款失败

	// 支付状态
	PayWayStatusPaid   = 1 //已支付
	PayWayStatusUnpaid = 2 //未支付

	// 退款方式
	RefundWayOnline  = 1 //结上退款
	RefundWayOffline = 2 // 线下退款

	// 退款类型
	RefundTypeBack = 1 //后台退款
	RefundTypeUser = 2 //用户退款

	// 订单类型
	OrderTypeRecharge = "recharge" // 充值订单
	OrderTypeOrder    = "order"    // 商品订单

)

var (
	// UmInc 用户余额（增加类型汇总）
	UmInc = []int32{
		UmIncAdmin,
		UmIncRecharge,
	}

	// UmDec 用户余额（减少类型汇总）
	UmDec = []int32{
		UmDecAdmin,
		UmDecRechargeRefund,
	}

	ChangeTypeDesc = map[int32]string{
		UmDecAdmin:          "平台减少余额",
		UmIncAdmin:          "平台增加余额",
		UmIncRecharge:       "充值增加余额",
		UmDecRechargeRefund: "充值订单退款减少余额",
	}

	RefundStatusDesc = map[int32]string{
		RefundStatusRefunding: "退款中",
		RefundStatusFail:      "退款失败",
		RefundStatusRefunded:  "已退款",
	}

	PayWayStatusDesc = map[int32]string{
		PayWayStatusPaid:   "已支付",
		PayWayStatusUnpaid: "未支付",
	}

	RefundTypeDesc = map[int32]string{
		RefundTypeBack: "后台退款",
		RefundTypeUser: "用户退款",
	}
)

// GetChangeObject 获取变动对象
func GetChangeObject(changeType int32) int32 {
	// UM 用户余额变动
	um := append(UmInc, UmDec...)

	if inArray(changeType, um) {
		return UM
	}
	return 0
}

// GetUserMoneyChangeTypeDesc 获取用户余额变动描述
func GetUserMoneyChangeTypeDesc(changeType int32) string {
	return ChangeTypeDesc[changeType]
}

func GetRefundTypeDesc(refundType int32) string {
	return RefundTypeDesc[refundType]
}

func GetRefundStatusDesc(refundStatus int32) string {
	return RefundStatusDesc[refundStatus]
}

func inArray(needle int32, haystack []int32) bool {
	for _, item := range haystack {
		if item == needle {
			return true
		}
	}
	return false
}
